package com.example.basecommon.utils;

import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.TextView;

import com.androidadvance.topsnackbar.TSnackbar;
import com.example.basecommon.R;

public class SnackBarUtils {
    public static void showError(View view, int resId) {
        showError(view, view.getContext().getString(resId));
    }

    public static void showError(View view, String msg) {
        show(view, msg, true);
    }

    public static void showNormal(View view, int resId) {
        showNormal(view, view.getContext().getString(resId));
    }

    public static void showNormal(View view, String msg) {
        show(view, msg, false);
    }

    public static void show(View view, String msg, boolean isError) {

        final TSnackbar snackbar = TSnackbar.make(view, msg, TSnackbar.LENGTH_LONG);
        snackbar.dismiss();
        snackbar.setActionTextColor(Color.YELLOW);
        View snackbarView = snackbar.getView();
        snackbarView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                snackbar.dismiss();
            }
        });
        snackbarView.setBackgroundColor(ContextCompat.getColor(view.getContext(), isError ? R.color.red : R.color.green));
        TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text);
        textView.setTextColor(Color.WHITE);
        snackbar.show();
    }
}
